package com.gdones.bootserver.bus.log.controller;


import com.gdones.bootserver.bus.log.dto.Log;
import com.gdones.bootserver.bus.log.service.ILogService;
import com.gdones.common.core.dto.MyPageBand;
import com.gdones.common.core.dto.MyPager;
import com.gdones.common.core.dto.MyResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 日志管理
 * @author GaoJingBo
 * @since 2023-03-23
 */
@RestController
@RequestMapping("/sys/log")
@Api(tags={"日志管理接口"})
@Slf4j
public class LogController {

    @Resource(name="logServiceImpl")
    private ILogService logService;

    @GetMapping("/pages")
    @ApiOperation("获取日志列表")
    public MyResult pages(Log syslog, MyPageBand pageBand){
        log.debug("--日志管理模块：获取日志列表");

        MyResult result = new MyResult();

        try {
            MyPager<Log> res = logService.myPage(syslog,pageBand);

            result.setMsg("查询成功！");
            result.setData(res);
        }catch (Exception e){
            result.setMsg("分页查询异常！");
            result.setCode("9999");
        }

        return result;
    }

    @GetMapping("/getModels")
    @ApiOperation("获取日志关联的所有模块信息")
    public MyResult getModels(){
        log.debug("--日志管理模块：获取日志关联的所有模块信息");

        MyResult result = new MyResult();

        try {
            List<String> res = logService.getModels();

            result.setMsg("查询成功！");
            result.setData(res);
        }catch (Exception e){
            result.setMsg("分页查询异常！");
            result.setCode("9999");
        }

        return result;
    }


}
